package com.mxpio.erp.plm.service.impl;

import com.mxpio.erp.common.enums.CommonEnums;
import com.mxpio.erp.common.plm.entity.ProjectTaskExecutionLog;
import com.mxpio.erp.common.plm.service.ProjectTaskExecutionLogService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.JpaUtil;
import com.mxpioframework.jpa.query.Criteria;
import com.mxpioframework.jpa.query.Operator;
import com.mxpioframework.security.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 任务的执行日志接口
 * @author qb
 * @date 2024-2.21
 */
@Service
public class ProjectTaskExecutionLogServiceImpl extends BaseServiceImpl<ProjectTaskExecutionLog> implements ProjectTaskExecutionLogService {

    @Override
    @Transactional(readOnly = true)
    public List<ProjectTaskExecutionLog> getByTaskCodeAndAuditStatus(String logType, String taskCode, String auditStatus) {
        return JpaUtil.linq(ProjectTaskExecutionLog.class)
                .equal("logType", logType)
                .equal("taskCode", taskCode)
                .equal("auditStatus", auditStatus)
                .list();
    }

    @Override
    @Transactional(readOnly = true)
    public Result<?> listone(String taskLogId) {
        ProjectTaskExecutionLog byId = this.getById(ProjectTaskExecutionLog.class, taskLogId);
        return Result.OK(byId);
//        Criteria criteria = Criteria.create().addCriterion("taskCode", Operator.EQ, taskCode);
//        List<ProjectTaskExecutionLog> list = this.list(ProjectTaskExecutionLog.class, criteria);
//        for (ProjectTaskExecutionLog projectTaskExecutionLog : list){
//            if (projectTaskExecutionLog.getIsAuditEnd().equals(CommonEnums.YesNo.NO.getCode())){
//                return Result.OK(projectTaskExecutionLog);
//            }
//        }
//        return null;
    }
}
